<template>
    <el-button v-if=checkAuthority() :type="isDeleteType()?'danger':'primary'" 
    :link="buttonLink"
     @click="onclick()">{{ buttonText }}</el-button>
</template>

<script setup lang="ts">
import constant from '@/utils/constant'
import store from '@/store'
import { useRoute } from 'vue-router'

const route = useRoute()

const props = defineProps({

	buttonText: {
		type: String,
		default: '查询'
	},

    buttonOpr:{
        type: String
    },

    buttonLink:{
        type:Boolean,
        default: false
    }
    
})

const emit = defineEmits(['emitEvent'])

const checkAuthority=() => {

    if(store.userStore.user.superAdmin == 1){
        return true
    } 
    
    if(!props.buttonOpr) return false
    const baseUri = route.path
    const oprArr = store.userStore.authorities[baseUri]
    if(!oprArr){
        return false
    }
    const index = oprArr.indexOf(props.buttonOpr)
   
    if(index == -1){
        return false
    } 
   
    return true
}

const onclick =() =>{
  emit("emitEvent")
}

const isDeleteType =() =>{
   return  props.buttonOpr == constant.ButtonTypeMap.DeleteKey ? true : false
}


</script>